package com.itheima;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class ServletDemo7 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建对象
        ServletContext servletContext = getServletContext();
        //获取参数
        Enumeration<String> ip = servletContext.getInitParameterNames();
        while (ip.hasMoreElements()){
            String s1 = ip.nextElement();
            String s2 = servletContext.getInitParameter(s1);
            System.out.println(s1+","+s2);
        }
        //获取硬盘地址
        String path1 = servletContext.getRealPath("/WEB-INF/classes/com");
        System.out.println(path1);
        String path2 = servletContext.getRealPath("/a.txt");
        System.out.println(path2);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req,resp);
    }
}
